﻿/**  版本信息模板在安装目录下，可自行修改。
* V_Message.cs
*
* 功 能： N/A
* 类 名： V_Message
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/2/22 18:24:16   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace BBPA.DAL
{
	/// <summary>
	/// 数据访问类:V_Message
	/// </summary>
	public partial class V_Message
	{
		public V_Message()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BBPA.Model.V_Message model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into V_Message(");
			strSql.Append("id,UserID,ReplayID,Title,TheContent,Dateandtime,Username,UserType,HasRead,HasReadDateandtime,ReceiveUserID,ReceiveUsername,ReceiveUserType,ReceiveUserIDStr,ReceiveUserTypeID,IsSendSMS,IsSendWeb,SendSMSstate,Mobile,StartSendSMSDateandtime,FinishSendSMSDateandtime,_SMS2Mobile)");
			strSql.Append(" values (");
			strSql.Append("@id,@UserID,@ReplayID,@Title,@TheContent,@Dateandtime,@Username,@UserType,@HasRead,@HasReadDateandtime,@ReceiveUserID,@ReceiveUsername,@ReceiveUserType,@ReceiveUserIDStr,@ReceiveUserTypeID,@IsSendSMS,@IsSendWeb,@SendSMSstate,@Mobile,@StartSendSMSDateandtime,@FinishSendSMSDateandtime,@_SMS2Mobile)");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@ReplayID", SqlDbType.Int,4),
					new SqlParameter("@Title", SqlDbType.NVarChar,100),
					new SqlParameter("@TheContent", SqlDbType.NVarChar,500),
					new SqlParameter("@Dateandtime", SqlDbType.DateTime),
					new SqlParameter("@Username", SqlDbType.NVarChar,50),
					new SqlParameter("@UserType", SqlDbType.TinyInt,1),
					new SqlParameter("@HasRead", SqlDbType.Bit,1),
					new SqlParameter("@HasReadDateandtime", SqlDbType.DateTime),
					new SqlParameter("@ReceiveUserID", SqlDbType.Int,4),
					new SqlParameter("@ReceiveUsername", SqlDbType.NVarChar,50),
					new SqlParameter("@ReceiveUserType", SqlDbType.TinyInt,1),
					new SqlParameter("@ReceiveUserIDStr", SqlDbType.VarChar,500),
					new SqlParameter("@ReceiveUserTypeID", SqlDbType.Int,4),
					new SqlParameter("@IsSendSMS", SqlDbType.Bit,1),
					new SqlParameter("@IsSendWeb", SqlDbType.Bit,1),
					new SqlParameter("@SendSMSstate", SqlDbType.TinyInt,1),
					new SqlParameter("@Mobile", SqlDbType.VarChar,11),
					new SqlParameter("@StartSendSMSDateandtime", SqlDbType.DateTime),
					new SqlParameter("@FinishSendSMSDateandtime", SqlDbType.DateTime),
					new SqlParameter("@_SMS2Mobile", SqlDbType.VarChar,11)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.UserID;
			parameters[2].Value = model.ReplayID;
			parameters[3].Value = model.Title;
			parameters[4].Value = model.TheContent;
			parameters[5].Value = model.Dateandtime;
			parameters[6].Value = model.Username;
			parameters[7].Value = model.UserType;
			parameters[8].Value = model.HasRead;
			parameters[9].Value = model.HasReadDateandtime;
			parameters[10].Value = model.ReceiveUserID;
			parameters[11].Value = model.ReceiveUsername;
			parameters[12].Value = model.ReceiveUserType;
			parameters[13].Value = model.ReceiveUserIDStr;
			parameters[14].Value = model.ReceiveUserTypeID;
			parameters[15].Value = model.IsSendSMS;
			parameters[16].Value = model.IsSendWeb;
			parameters[17].Value = model.SendSMSstate;
			parameters[18].Value = model.Mobile;
			parameters[19].Value = model.StartSendSMSDateandtime;
			parameters[20].Value = model.FinishSendSMSDateandtime;
			parameters[21].Value = model._SMS2Mobile;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BBPA.Model.V_Message model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update V_Message set ");
			strSql.Append("id=@id,");
			strSql.Append("UserID=@UserID,");
			strSql.Append("ReplayID=@ReplayID,");
			strSql.Append("Title=@Title,");
			strSql.Append("TheContent=@TheContent,");
			strSql.Append("Dateandtime=@Dateandtime,");
			strSql.Append("Username=@Username,");
			strSql.Append("UserType=@UserType,");
			strSql.Append("HasRead=@HasRead,");
			strSql.Append("HasReadDateandtime=@HasReadDateandtime,");
			strSql.Append("ReceiveUserID=@ReceiveUserID,");
			strSql.Append("ReceiveUsername=@ReceiveUsername,");
			strSql.Append("ReceiveUserType=@ReceiveUserType,");
			strSql.Append("ReceiveUserIDStr=@ReceiveUserIDStr,");
			strSql.Append("ReceiveUserTypeID=@ReceiveUserTypeID,");
			strSql.Append("IsSendSMS=@IsSendSMS,");
			strSql.Append("IsSendWeb=@IsSendWeb,");
			strSql.Append("SendSMSstate=@SendSMSstate,");
			strSql.Append("Mobile=@Mobile,");
			strSql.Append("StartSendSMSDateandtime=@StartSendSMSDateandtime,");
			strSql.Append("FinishSendSMSDateandtime=@FinishSendSMSDateandtime,");
			strSql.Append("_SMS2Mobile=@_SMS2Mobile");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@ReplayID", SqlDbType.Int,4),
					new SqlParameter("@Title", SqlDbType.NVarChar,100),
					new SqlParameter("@TheContent", SqlDbType.NVarChar,500),
					new SqlParameter("@Dateandtime", SqlDbType.DateTime),
					new SqlParameter("@Username", SqlDbType.NVarChar,50),
					new SqlParameter("@UserType", SqlDbType.TinyInt,1),
					new SqlParameter("@HasRead", SqlDbType.Bit,1),
					new SqlParameter("@HasReadDateandtime", SqlDbType.DateTime),
					new SqlParameter("@ReceiveUserID", SqlDbType.Int,4),
					new SqlParameter("@ReceiveUsername", SqlDbType.NVarChar,50),
					new SqlParameter("@ReceiveUserType", SqlDbType.TinyInt,1),
					new SqlParameter("@ReceiveUserIDStr", SqlDbType.VarChar,500),
					new SqlParameter("@ReceiveUserTypeID", SqlDbType.Int,4),
					new SqlParameter("@IsSendSMS", SqlDbType.Bit,1),
					new SqlParameter("@IsSendWeb", SqlDbType.Bit,1),
					new SqlParameter("@SendSMSstate", SqlDbType.TinyInt,1),
					new SqlParameter("@Mobile", SqlDbType.VarChar,11),
					new SqlParameter("@StartSendSMSDateandtime", SqlDbType.DateTime),
					new SqlParameter("@FinishSendSMSDateandtime", SqlDbType.DateTime),
					new SqlParameter("@_SMS2Mobile", SqlDbType.VarChar,11)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.UserID;
			parameters[2].Value = model.ReplayID;
			parameters[3].Value = model.Title;
			parameters[4].Value = model.TheContent;
			parameters[5].Value = model.Dateandtime;
			parameters[6].Value = model.Username;
			parameters[7].Value = model.UserType;
			parameters[8].Value = model.HasRead;
			parameters[9].Value = model.HasReadDateandtime;
			parameters[10].Value = model.ReceiveUserID;
			parameters[11].Value = model.ReceiveUsername;
			parameters[12].Value = model.ReceiveUserType;
			parameters[13].Value = model.ReceiveUserIDStr;
			parameters[14].Value = model.ReceiveUserTypeID;
			parameters[15].Value = model.IsSendSMS;
			parameters[16].Value = model.IsSendWeb;
			parameters[17].Value = model.SendSMSstate;
			parameters[18].Value = model.Mobile;
			parameters[19].Value = model.StartSendSMSDateandtime;
			parameters[20].Value = model.FinishSendSMSDateandtime;
			parameters[21].Value = model._SMS2Mobile;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from V_Message ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BBPA.Model.V_Message GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,UserID,ReplayID,Title,TheContent,Dateandtime,Username,UserType,HasRead,HasReadDateandtime,ReceiveUserID,ReceiveUsername,ReceiveUserType,ReceiveUserIDStr,ReceiveUserTypeID,IsSendSMS,IsSendWeb,SendSMSstate,Mobile,StartSendSMSDateandtime,FinishSendSMSDateandtime,_SMS2Mobile from V_Message ");
			strSql.Append(" where ");
			SqlParameter[] parameters = {
			};

			BBPA.Model.V_Message model=new BBPA.Model.V_Message();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BBPA.Model.V_Message DataRowToModel(DataRow row)
		{
			BBPA.Model.V_Message model=new BBPA.Model.V_Message();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["UserID"]!=null && row["UserID"].ToString()!="")
				{
					model.UserID=int.Parse(row["UserID"].ToString());
				}
				if(row["ReplayID"]!=null && row["ReplayID"].ToString()!="")
				{
					model.ReplayID=int.Parse(row["ReplayID"].ToString());
				}
				if(row["Title"]!=null)
				{
					model.Title=row["Title"].ToString();
				}
				if(row["TheContent"]!=null)
				{
					model.TheContent=row["TheContent"].ToString();
				}
				if(row["Dateandtime"]!=null && row["Dateandtime"].ToString()!="")
				{
					model.Dateandtime=DateTime.Parse(row["Dateandtime"].ToString());
				}
				if(row["Username"]!=null)
				{
					model.Username=row["Username"].ToString();
				}
				if(row["UserType"]!=null && row["UserType"].ToString()!="")
				{
					model.UserType=int.Parse(row["UserType"].ToString());
				}
				if(row["HasRead"]!=null && row["HasRead"].ToString()!="")
				{
					if((row["HasRead"].ToString()=="1")||(row["HasRead"].ToString().ToLower()=="true"))
					{
						model.HasRead=true;
					}
					else
					{
						model.HasRead=false;
					}
				}
				if(row["HasReadDateandtime"]!=null && row["HasReadDateandtime"].ToString()!="")
				{
					model.HasReadDateandtime=DateTime.Parse(row["HasReadDateandtime"].ToString());
				}
				if(row["ReceiveUserID"]!=null && row["ReceiveUserID"].ToString()!="")
				{
					model.ReceiveUserID=int.Parse(row["ReceiveUserID"].ToString());
				}
				if(row["ReceiveUsername"]!=null)
				{
					model.ReceiveUsername=row["ReceiveUsername"].ToString();
				}
				if(row["ReceiveUserType"]!=null && row["ReceiveUserType"].ToString()!="")
				{
					model.ReceiveUserType=int.Parse(row["ReceiveUserType"].ToString());
				}
				if(row["ReceiveUserIDStr"]!=null)
				{
					model.ReceiveUserIDStr=row["ReceiveUserIDStr"].ToString();
				}
				if(row["ReceiveUserTypeID"]!=null && row["ReceiveUserTypeID"].ToString()!="")
				{
					model.ReceiveUserTypeID=int.Parse(row["ReceiveUserTypeID"].ToString());
				}
				if(row["IsSendSMS"]!=null && row["IsSendSMS"].ToString()!="")
				{
					if((row["IsSendSMS"].ToString()=="1")||(row["IsSendSMS"].ToString().ToLower()=="true"))
					{
						model.IsSendSMS=true;
					}
					else
					{
						model.IsSendSMS=false;
					}
				}
				if(row["IsSendWeb"]!=null && row["IsSendWeb"].ToString()!="")
				{
					if((row["IsSendWeb"].ToString()=="1")||(row["IsSendWeb"].ToString().ToLower()=="true"))
					{
						model.IsSendWeb=true;
					}
					else
					{
						model.IsSendWeb=false;
					}
				}
				if(row["SendSMSstate"]!=null && row["SendSMSstate"].ToString()!="")
				{
					model.SendSMSstate=int.Parse(row["SendSMSstate"].ToString());
				}
				if(row["Mobile"]!=null)
				{
					model.Mobile=row["Mobile"].ToString();
				}
				if(row["StartSendSMSDateandtime"]!=null && row["StartSendSMSDateandtime"].ToString()!="")
				{
					model.StartSendSMSDateandtime=DateTime.Parse(row["StartSendSMSDateandtime"].ToString());
				}
				if(row["FinishSendSMSDateandtime"]!=null && row["FinishSendSMSDateandtime"].ToString()!="")
				{
					model.FinishSendSMSDateandtime=DateTime.Parse(row["FinishSendSMSDateandtime"].ToString());
				}
				if(row["_SMS2Mobile"]!=null)
				{
					model._SMS2Mobile=row["_SMS2Mobile"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,UserID,ReplayID,Title,TheContent,Dateandtime,Username,UserType,HasRead,HasReadDateandtime,ReceiveUserID,ReceiveUsername,ReceiveUserType,ReceiveUserIDStr,ReceiveUserTypeID,IsSendSMS,IsSendWeb,SendSMSstate,Mobile,StartSendSMSDateandtime,FinishSendSMSDateandtime,_SMS2Mobile ");
			strSql.Append(" FROM V_Message ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,UserID,ReplayID,Title,TheContent,Dateandtime,Username,UserType,HasRead,HasReadDateandtime,ReceiveUserID,ReceiveUsername,ReceiveUserType,ReceiveUserIDStr,ReceiveUserTypeID,IsSendSMS,IsSendWeb,SendSMSstate,Mobile,StartSendSMSDateandtime,FinishSendSMSDateandtime,_SMS2Mobile ");
			strSql.Append(" FROM V_Message ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM V_Message ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from V_Message T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "V_Message";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

